#include<bits/stdc++.h>
using namespace std;
int t,n,ans,maxx,a[200001],s[200001];
void dfs(int x,int l,int r){
    if(x==n+1){
        ans=0;
        int y=l,z=r;
        for(int i=n;i>=1;i--){
            if(i!=y&&s[i]==1){
                if(a[i]==a[y]) ans+=a[i];
                y=i;
            }
            if(i!=z&&s[i]==2){
                if(a[i]==a[z]) ans+=a[i];
                z=i;
            }
        }
        maxx=max(maxx,ans);
        return;
    }
    s[x]=1;
    dfs(x+1,x,r);
    s[x]=2;
    dfs(x+1,l,x);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        ans=0; maxx=0;
        dfs(1,0,0);
        cout<<maxx<<endl;
    }
    return 0;
}
